package com.lcj.dr.controller;

import com.github.pagehelper.PageInfo;
import com.lcj.common.util.Result;
import com.lcj.dr.controller.form.DriverFineForm;
import com.lcj.dr.controller.form.SearchFineForm;
import com.lcj.dr.db.pojo.DriverFineEntity;
import com.lcj.dr.service.DriverFineService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/fine")
@Tag(name = "DriverFineController", description = "司机罚款管理Web接口")
public class DriverFineController {

    @Resource
    private DriverFineService driverFineService;

    @PostMapping("/addOrUpdateDriverFine")
    @Operation(summary = "插入或更新司机罚款")
    public Result addOrUpdate(@RequestBody @Valid DriverFineForm form) {
        Integer res = driverFineService.addOrUpdate(form);
        return Result.ok().put("rows", res);
    }

    @PostMapping("/deleteDriverFine")
    @Operation(summary = "删除司机罚款")
    public Result delete(@RequestBody @Valid DriverFineForm form) {
        Integer res = driverFineService.deleteFine(form);
        return Result.ok().put("rows", res);
    }

    @PostMapping("/selectDriverFine")
    @Operation(summary = "查询司机罚款")
    public Result selectPage(@RequestBody @Valid SearchFineForm form) {
        PageInfo<DriverFineEntity> pageInfo = driverFineService.selectPage(form);
        return Result.ok().put("result", pageInfo);
    }

}